/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 updated 2 Dec 2010
 by Tom Igoe
 
 This example code is in the public domain.
 	 
 */

#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(10, OUTPUT);
  delay(1000);
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  if (SD.exists("test.txt")) 
  {
    Serial.println("test.txt exists.");
    SD.remove("test.txt");
  }
  myFile = SD.open("test.txt", FILE_WRITE);

  byte data[512];
  for(int i=0;i<512;i++)
  {
    data[i]=(byte)i; 
  }
  myFile = SD.open("test.txt", FILE_WRITE);
      if (!myFile) { return;}
  //should take 35 minutes!
  for(int j=0;j<70;j++)
  {
    Serial.println(j);



    // if the file opened okay, write to it:

      Serial.println(millis());
      for(int i=0;i<2000;i++)
      {
        myFile.write(data,512);
//              Serial.println(i);
      }
      Serial.println(millis());
      // close the file:

      //Serial.println("done.");
   
  }
  myFile.close();
}

void loop()
{
}



